/*
 * @Author: your name
 * @Date: 2021-06-26 09:52:14
 * @LastEditTime: 2021-06-27 15:34:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \6.26作业\yyds\db\mysql.js
 */
const mysql = require("mysql")

const con = mysql.createConnection({
    port: "3306",
    host: "localhost",
    user: "root",
    password: "root",
    database: "6.21作业人"
})

con.connect()

function query(sql) {
    return new Promise((resolve, reject) => {
        con.query(sql, (err, data) => {
            if (err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

module.exports=query

const mock = require('mockjs')
const {list} = mock.mock({
    "list|10":[
        {
            title: "@ctitle(5,10)",
            word: "@cword(10,20)",
            "money|1-1000": 1,
            image: "@image(100x100,@color)",
            "sales|1-10000": 1,
            "stock|1-10000": 1,
        }
    ]
})
list.forEach(item => {
    let sql = `insert into shops(title,word,money,image,sales,stock) values("${item.title}","${item.word}","${item.money}","${item.image}","${item.sales}","${item.stock}")`
    console.log(sql)
})